<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改图书')"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-edit" th:object="${goods}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">书名：</label>
            <div class="col-sm-8">
                <input name="name" th:field="*{name}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">类型：</label>
            <div class="col-sm-8">
                <select id="type" class="form-control" >
                    <option th:each="type:${types}" th:value="${type.id}"
                            th:text="${type.name}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">作者：</label>
            <div class="col-sm-8">
                <input name="author" th:field="*{author}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">价格：</label>
            <div class="col-sm-8">
                <input name="price" th:field="*{price}" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">简介：</label>
            <div class="col-sm-8">
                <textarea name="description" class="form-control">[[*{description}]]</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">封面：</label>
            <div class="col-sm-8">
                <input name="imageUrl" th:field="*{imageUrl}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>

<script type="text/javascript">
    var prefix = ctx + "demo/goods";
    $("#form-goods-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {

            var data = $("#form-goods-edit").serializeArray();

            var type = $.form.selectSelects("type");
            data.push({"name": "type", "value": type});
            $.operate.save(prefix + "/edit", data);
        }
    }

    $(function () {
        $('#type').select2({
            placeholder: "请选择图书类型",
            allowClear: true
        });
    })
</script>
</body>
</html>